package com.test.controller;

import com.alibaba.fastjson.JSON;
import com.test.util.EmailUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.Map;

/**
 * @packageName: com.test.controller
 * @name: MailController
 * @description:
 * @author: 董定卓
 * @dateTime: 2018/9/18 11:01
 */
@Controller
@RequestMapping("mail")
public class MailController {

    @RequestMapping("send")
    @ResponseBody
    public Object sendMail(@RequestParam Map<String, Object> map) {
        Map<String, Object> result = new HashMap<>();
        Object username = map.get("username");
        if (username == null) {
            result.put("code", "101");
            result.put("msg", "username is null");
            return JSON.toJSONString(result);
        }
        Object topic = map.get("topic");
        if (topic == null) {
            result.put("code", "102");
            result.put("msg", "topic is null");
            return JSON.toJSONString(result);
        }
        Object content = map.get("content");
        if (content == null) {
            result.put("code", "103");
            result.put("msg", "content is null");
            return JSON.toJSONString(result);
        }
        EmailUtils.emailUtils.sendEmail("dong.test@qq.com", username.toString(), topic.toString(), content.toString());
        result.put("code", "200");
        result.put("msg", "send success");

        return JSON.toJSONString(result);
    }

}
